package com.example.demo.Service;

import com.example.demo.entity.User;
import com.example.demo.mapper.UserRepository;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    private final UserRepository userRepository;

    public UserService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    public boolean register(User user) {
        try {
            userRepository.save(user);
            return true;
        } catch (Exception e) {
            return false;
        }
    }

    public boolean login(String username, String password) {
        try {
            User user = userRepository.findByUsername(username);
            return user.getPassword().equals(password);
        } catch (Exception e) {
            return false;
        }
    }
}
